package github.sf.fw.dbread.model;

import github.sf.fw.tools.db.model.DataBaseInfo;
import github.sf.fw.tools.db.model.TableInfo;
import github.sf.fw.utils.StrUtil;
import org.junit.platform.commons.util.StringUtils;

import java.util.List;
import java.util.Optional;

public class LibraryInfoShow {
    public static void showLibrary(DataBaseInfo schemaInfo) {
        System.out.println(StrUtil.format("schema name is {},table count is {}", schemaInfo.getName(), schemaInfo.getTableCount()));
        List<TableInfo> tableInfoList = schemaInfo.getTableInfoList();
        Optional.ofNullable(tableInfoList).ifPresent(tableInfos -> {
            for (TableInfo tableInfo : tableInfos) {
                showTable(schemaInfo.getName(), tableInfo);
            }
        });
    }

    public static void showTable(String schemaName, TableInfo tableInfo) {
        if (StringUtils.isNotBlank(schemaName)) {
            System.out.println(StrUtil.format("schema name is {},table name is {}", schemaName, tableInfo.getName()));
        } else {
            System.out.println(StrUtil.format("table name is {}", tableInfo.getName()));
        }
    }
}
